<?php

namespace hotel\common\models;

use Yii;

/**
 * This is the model class for table "question_typess".
 *
 * @property int $id
 * @property string $appid
 * @property string $title
 * @property int $num
 */
class QuestionType extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'question_type';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['appid', 'title'], 'string', 'max' => 100],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'appid' => 'Appid',
            'title' => 'Title'
        ];
    }

    /**
     * @param $arr
     * @return bool
     * 插入数据
     */
    public static function setData($arr,$appid){
        $model = new self();
        $model->setAttributes($arr);
        $model->appid = $appid;
        if($model->save()){
            return true;
        }
        return false;
    }


    /**
     * @param $arr
     * @return bool
     * 插入数据
     */
    public static function updateData($arr){
        $model = self::findOne($arr['id']);
        $model->setAttributes($arr);
        if($model->save()){
            return true;
        }
        return false;
    }



    /**
     * @param $params
     * @return mixed
     */
    public static function lists($params,$appid){
        $page = 1;
        $limit = 10;
        extract($params);
        //分页
        $offset = ($page - 1) * $limit;
        $model = self::find();

        $total	= $model->where("appid = '$appid'")->count();
        $data = $model->where("appid = '$appid'")->offset($offset)->limit($limit)->asArray()->all();

        $res['list'] = $data;
        $res['total'] = $total;
        return $res;
    }
}
